<%--
  Created by IntelliJ IDEA.
  User: asus
  Date: 2020/9/10
  Time: 14:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../index.jsp"%>

<head lang="en">

    <title>超市订单管理系统</title>
    <link type="text/css" rel="stylesheet" href="../../../statics/css/style.css" />
    <link type="text/css" rel="stylesheet" href="../../../statics/css/public.css" />
</head>

<body>
<div class="right">
    <div class="location">
        <strong>你现在所在的位置是:</strong>
        <span>用户管理页面</span>
    </div>
    <div class="search">
            <span>用户名：</span>
            <input id ="queryname" class="input-text"	type="text">

            <span>用户角色：</span>
            <select name="queryUserRole" id="queryRolename">

                <option value="0">--请选择--</option>


            </select>
            <input type="hidden" name="pageIndex" value="1"/>
            <input	value="查 询" type="submit" id="searchbutton">
            <a href="toUseradd" >添加用户</a>
    </div>
    <!--用户-->
    <table class="providerTable" cellpadding="0" cellspacing="0">
        <tr class="firstTr">
            <th width="10%">用户编码</th>
            <th width="20%">用户名称</th>
            <th width="10%">性别</th>
            <th width="10%">生日</th>
            <th width="10%">电话</th>
            <th width="10%">用户角色</th>
            <th width="30%">操作</th>
        </tr>


    </table>

    <div class="page-bar">
        <ul class="page-num-ul clearfix">
            <li>共<span id="totalCount"></span>条记录&nbsp;&nbsp; <span id="currentPage"></span>/<span id="totalPage"></span>页</li>

            <a href="javascript:void(0)" class="first">首页</a>
            <a href="javascript:void(0)" class="prev">上一页</a>


            <a href="javascript:void(0)" class="next">下一页</a>
            <a href="javascript:void(0)" class="last">最后一页</a>

            &nbsp;&nbsp;
        </ul>
        <span class="page-go-form"><label>跳转至</label>
	     <input type="text" name="inputPage" id="inputPage" class="page-key" />页
	     <button type="button" class="page-btn" onClick=''>GO</button>
		</span>
    </div>
    <div class="zhezhao"></div>
    <div class="remove" id="removeUse">
        <div class="removerChid">
            <h2>提示</h2>
            <div class="removeMain">
                <p>确定删除此用户吗？</p>
                <a href="#" id="yes">确定</a>
                <a href="javascript:void(0)" id="no">取消</a>
            </div>
        </div>
    </div>

</div>
</section>

<script src="../../../statics/js/jquery-1.9.1.min.js"></script>
<script>

    var currentPage = 1;
    $(function () {
        bindData(currentPage);
        bindEvent();
    })

    function bindData(currentPage) {
        var name = $("#queryname").val();
        var userRole = $("#queryRolename").val();
        $.post("showUser", {
            "name": name,
            "userRole": userRole,
            "currentPage": currentPage
        }, function (msg) {
            var str = "";

            $(msg.list).each(function (i) {
                var p = msg.list[i]
                str += "<tr>"
                str += "<td>"
                str += "<span>" + p.usercode + "</span>"
                str += "</td>"
                str += "<td>"
                str += "<span>" + p.username + "</span>"
                str += "</td>"
                str += "<td>"
                str += "<span>"
                str += p.gender == 1 ? "男" : "女"
                str += "</span>"
                str += "</td>"
                str += "<td>"
                str += "<span>" + formatDate(p.birthday) + "</span>"
                str += "</td>"
                str += "<td>"
                str += "<span>" + p.phone + "</span>"
                str += "</td>"
                str += "<td>"
                str += "<span>" + p.role.rolename + "</span>"
                str += "</td>"
                str += "<td>"
                str += '<span><a class="viewUser" href="javascript:void(0);" data-id="'+p.id+'"><img src="../../../statics/images/read.png" alt="查看" title="查看"/></a></span>'
                str += '<span><a class="modifyUser" href="javascript:void(0);"><img src="../../../statics/images/xiugai.png" alt="修改" title="修改"/></a></span>'
                str += '<span><a class="deleteUser" href="javascript:void(0); data-id="'+p.id+'"><img src="../../../statics/images/schu.png" alt="删除" title="删除"/></a></span>'
                str += "</td>"
                str += "</tr>"
            })

            $(".providerTable tr:not(:first)").remove();
            $(".providerTable").append(str);
            $("#totalCount").html(msg.totalCount);
            $("#totalPage").html(msg.totalPage);
            $("#currentPage").html(currentPage);

        }, "json")
    }

        function bindEvent(){
            var str = "";
            $.post("showRole",
                function (msg) {
                    $(msg).each(function (i) {
                        var p = msg[i]
                        str += "<option value=" + p.id + ">"
                        str += p.rolename
                        str += "</option>"

                    })
                    $("#queryRolename").append(str);

                },"json")

            $(".providerTable").delegate(".viewUser","click",function(){
                var id = $(this).data("id");
                window.location = "userview/"+id;
            })

            $("#searchbutton").click(function(){
                currentPage = 1;
                bindData(currentPage);
            })

            $(".first").click(function () {
                currentPage = 1;
                bindData(currentPage);
            })

            $(".prev").click(function () {
                if(currentPage == 1){
                    return;
                }
                currentPage--;
                bindData(currentPage);
            })

            $(".next").click(function () {
                if(currentPage == $("#totalPage").val()){
                    return;
                }
                currentPage++;
                bindData(currentPage);
            })

            $(".last").click(function () {
                currentPage = parseInt($("#totalPage").val());
                bindData(currentPage);
            })

            $(".page-btn").click(function () {
                var page = $("#inputPage").val();
                bindData(parseInt(page));
            })

            var id = 0;

            $(".providerTable").delegate(".deleteUser","click",function() {
               $(".zhezhao,.remove") .show();
                id = $(this).data("id");
            })

            $("#yes").click(function(){
                window.location = "smbmsServlet?mode=deleteuser&id="+id
            })


            //点击no
            $("#no").click(function(){
                $(".zhezhao,.remove").hide()
            })
        }

    function  formatDate(obj) {
        var date = new Date();
        date.setTime(obj);
        return date.getFullYear()+"年"+(date.getMonth()+1)+"月"+date.getDate()
    }

</script>


<%@include file="../foot.jsp"%>
